package com.ljf.game.config;

import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 描述 :为tomcat自8.5.x系列的：8.5.12 之后版本、8.0.x系列的：8.0.42 之后版本、7.0.x系列的：7.0.76 之后版本对URL参数做了比较规范的限制，
 * 必须遵循RFC 7230 and RFC 3986规范，对于非保留字字符（json格式的请求参数）必须做转义操作，
 * 否则会抛出Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986错误信息。
 * <p>
 * 版本     作者     时间      内容
 * 1.0      lijinfeng       2025-05-12 16:12     create
 */
@Configuration
public class TomcatConfigurer {
    @Bean
    public TomcatServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers((Connector connector) -> {
            connector.setProperty("relaxedPathChars", "\"<>[\\]^`{|}");
            connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}");
        });
        return factory;
    }
}
